﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.OA.Notification.NotificationCategoryMappingDepartment;
using BCService.Utils;
using BCService.OA.Notification.NotificationCategoryMappingDepartment;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.Notification.NotificationCategoryMappingDepartment
{
    /// <summary>
    /// OA系统通知分类与部门关系映射
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class NotificationCategoryMappingDepartmentController : ManagementBaseController
    {
        private readonly INotificationCategoryMappingDepartmentService notificationCategoryMappingDepartmentService;

        public NotificationCategoryMappingDepartmentController(INotificationCategoryMappingDepartmentService notificationCategoryMappingDepartmentService)
        {
            this.notificationCategoryMappingDepartmentService = notificationCategoryMappingDepartmentService;
        }

        #region 添加OA系统通知分类与部门关系映射
        /// <summary>
        ///  添加OA系统通知分类与部门关系映射
        /// </summary>
        /// <param name="requestDto">OA系统通知分类与部门关系映射信息</param>
        /// <response code="201">添加OA系统通知分类与部门关系映射成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统通知分类与部门关系映射")]
        [ProducesResponseType(typeof(NotificationCategoryMappingDepartmentDto), 201)]
        public IActionResult Post(
            [FromBody]NotificationCategoryMappingDepartmentRequestDto requestDto)
        {
            var result = this.notificationCategoryMappingDepartmentService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/NotificationCategoryMappingDepartment/{0}", result.NotificationCategoryMappingDepartmentId), result);
        }
        #endregion

        #region 修改OA系统通知分类与部门关系映射
        /// <summary>
        ///  修改OA系统通知分类与部门关系映射
        /// </summary>
        /// <param name="notificationCategoryMappingDepartmentId">OA系统通知分类与部门关系映射Id</param>
        /// <param name="requestDto">OA系统通知分类与部门关系映射信息</param>
        /// <response code="200">修改OA系统通知分类与部门关系映射成功</response>
        /// <returns></returns>
        [HttpPut("{notification_category_mapping_department_id}")]
        [Log("修改OA系统通知分类与部门关系映射")]
        [ProducesResponseType(typeof(NotificationCategoryMappingDepartmentDto), 200)]
        public IActionResult Post([FromRoute(Name = "notification_category_mapping_department_id")]long notificationCategoryMappingDepartmentId, [FromBody]NotificationCategoryMappingDepartmentRequestDto requestDto)
        {
            NotificationCategoryMappingDepartmentPutDto putDto = requestDto.As<NotificationCategoryMappingDepartmentPutDto>();
            putDto.NotificationCategoryMappingDepartmentId = notificationCategoryMappingDepartmentId;
            return this.Ok(this.notificationCategoryMappingDepartmentService.Update(putDto));
        }
        #endregion

        #region 删除OA系统通知分类与部门关系映射
        /// <summary>
        ///  删除OA系统通知分类与部门关系映射
        /// </summary>
        /// <param name="notificationCategoryMappingDepartmentId">OA系统通知分类与部门关系映射Id</param>
        /// <response code="204">删除OA系统通知分类与部门关系映射成功</response>
        /// <returns></returns>
        [HttpDelete("{notification_category_mapping_department_id}")]
        [Log("删除OA系统通知分类与部门关系映射")]
        public IActionResult Delete([FromRoute(Name = "notification_category_mapping_department_id")]long notificationCategoryMappingDepartmentId)
        {
            this.notificationCategoryMappingDepartmentService.Delete(notificationCategoryMappingDepartmentId);
            return this.NoContent();
        }
        #endregion

        #region 获取OA系统通知分类与部门关系映射
        /// <summary>
        ///  获取OA系统通知分类与部门关系映射
        /// </summary>
        /// <param name="notificationCategoryMappingDepartmentId">OA系统通知分类与部门关系映射Id</param>
        /// <response code="200">获取OA系统通知分类与部门关系映射</response>
        /// <returns></returns>
        [HttpGet("{notification_category_mapping_department_id}")]
        [ProducesResponseType(typeof(NotificationCategoryMappingDepartmentDto), 200)]
        public IActionResult Get([FromRoute(Name = "notification_category_mapping_department_id")]long notificationCategoryMappingDepartmentId)
        {
            return this.Ok(this.notificationCategoryMappingDepartmentService.GetEntity(notificationCategoryMappingDepartmentId));
        }
        #endregion

        #region 获取OA系统通知分类与部门关系映射列表
        /// <summary>
        ///  获取OA系统通知分类与部门关系映射列表
        /// </summary>
        /// <response code="200">获取OA系统通知分类与部门关系映射列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(NotificationCategoryMappingDepartmentDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.notificationCategoryMappingDepartmentService.GetList());
        }
        #endregion

        #region 获取OA系统通知分类与部门关系映射（分页）
        /// <summary>
        ///  获取OA系统通知分类与部门关系映射（分页）
        /// </summary>
        /// <param name="notificationCategoryName">通知分类名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统通知分类与部门关系映射（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<NotificationCategoryMappingDepartmentDto>), 200)]
        public IActionResult Query([FromQuery(Name = "notification_category_name")]string notificationCategoryName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.notificationCategoryMappingDepartmentService.Query(notificationCategoryName,start,end,pageIndex, pageSize));
        }
        #endregion

    }
}
